package com.wanrue.prometheus.controller;

import com.wanrue.prometheus.service.ApiService;
import com.wanrue.prometheus.pojo.Instance;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping
public class ApiController {

    private final Map<String, ApiService> apiServiceMap;

    public ApiController(Map<String, ApiService> apiServiceMap) {
        this.apiServiceMap = apiServiceMap;
    }

    @GetMapping("{mode}/{service}")
    public List<Instance> discovery(@PathVariable String mode, @PathVariable String service) throws Exception {
        ApiService apiService = apiServiceMap.get(mode);
        return apiService.discovery(service);
    }

}
